package com.codejoys.monitor.service.impl;

import com.codejoys.monitor.domain.SysConfig;
import com.codejoys.monitor.domain.SysConfigExample;
import com.codejoys.monitor.exception.SysException;
import com.codejoys.monitor.mapper.SysConfigMapper;
import com.codejoys.monitor.service.SysConfigService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class SysConfigServiceImpl implements SysConfigService {
    @Autowired
    SysConfigMapper sysConfigMapper;

    
    private static final Logger logger = LoggerFactory.getLogger(SysConfigServiceImpl.class);
    
    //新增系统配置
    @Override
    public void add(SysConfig sysConfig) {
        if(sysConfig.getName()!= null && sysConfig.getValue()!= null && sysConfig.getRemark()!= null){
            SysConfigExample example  = new SysConfigExample();
            example.createCriteria().andNameEqualTo(sysConfig.getName());
            List<SysConfig> sysConfigs = sysConfigMapper.selectByExample(example);//从系统信息表中查询数据
            if(sysConfigs.size() == 0){//如果配置项不重复
                sysConfigMapper.insertSelective(sysConfig);
            }else {
                throw new SysException(40001,"配置项名称重复，请重新输入" );
            }

        }else {
            throw new SysException(40000,"输入信息有空项，请重新输入");
        }


    }
}
